import hashlib
#
m = hashlib.md5(b'123456')
print(m)
#
print(m.hexdigest())

m1 = hashlib.md5()
m1.update(b'12')
print(m1.hexdigest())
m1.update(b'34')
print(m1.hexdigest())
m1.update(b'56')
print(m1.hexdigest())

# Example
print('--------Example----------')
def check_md5(file):
    m = hashlib.md5()
    with open(file, mode='rb') as fr:
        while True:
            data = fr.read(4*1024)
            if not data:
                break
            else:
                m.update(data)
            # print(m.hexdigest())
    return m.hexdigest()

if __name__ == "__main__":
    result = check_md5('/usr/bin/ls')
    print(result)
